package top.carrotguo.weibo.presenter;

import com.sina.weibo.sdk.auth.Oauth2AccessToken;

import java.util.PrimitiveIterator;

import top.carrotguo.weibo.adapter.PersonPagerAdapter;
import top.carrotguo.weibo.bean.HomeTimeLine;
import top.carrotguo.weibo.contract.PersonHomeContract;
import top.carrotguo.weibo.model.PersonHomeModel;
import top.carrotguo.weibo.retrofit.callback.BaseCallback;
import top.carrotguo.weibo.retrofit.callback.ErrorInfo;

public class PersonHomePresenter extends BasePresenter<PersonHomeContract.View>
        implements PersonHomeContract.Presenter {

    private PersonHomeContract.Model mModel;

    public PersonHomePresenter(){
        mModel = new PersonHomeModel();
    }

    @Override
    public void getBlogList(Oauth2AccessToken token, String uid) {
        String accessToken = token.getToken();
        mModel.getBlogList(accessToken, uid, new BaseCallback<HomeTimeLine, ErrorInfo>() {
            @Override
            public void onSuccessed(HomeTimeLine successInfo) {
                if (getView() != null) {
                    if (successInfo.getStatuses().size()>0) {
                        getView().getBlogsSuccess(successInfo);
                    } else {
                        getView().showBlogsEmpty();
                    }
                }
            }

            @Override
            public void onError(ErrorInfo errorInfo) {
                if (getView() != null) {
                    getView().getBlogsError(errorInfo);
                }
            }
        });
    }
}
